<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>弓友之家</title>
    <link rel="stylesheet" href="css/mui.css" />
    <link rel="stylesheet" href="fonts/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		<h1 class="mui-title">地址管理</h1>
	</header>
	<div class="mui-content">
		<form class="address">
			<div class="form-item mui-clearfix">
				<label><span>*</span>姓名：</label>
				<input type="text" id="name" placeholder="点击输入姓名" />
			</div>
			<div class="form-item mui-clearfix">
				<label><span>*</span>性别：</label>
				<select id="sex">
					<option data-type="1">男</option>
					<option data-type="2">女</option>
					<option data-type="0">未知</option>
				</select>
			</div>
			<div class="form-item mui-clearfix">
				<label><span>*</span>联系方式：</label>
				<input type="number" id="tel" placeholder="点击输入电话" />
			</div>
			<div class="form-item mui-clearfix">
				<label><span>*</span>邮编：</label>
				<input type="text" id="email" placeholder="点击输入邮编" />
			</div>
			<div class="form-item mui-clearfix">
				<label><span>*</span>住址：</label>
				<div data-toggle="distpicker" class="distpicker">
					<select id="province"></select>
					<select id="city"></select>
					<select id="area"></select>
				</div>
			</div>
			<div class="form-item mui-clearfix">
				<label><span>*</span>详细地址：</label>
				<textarea id="address"></textarea>
			</div>
			<button type="button" onclick="sub()">确认提交</button>
		</form>
	</div>
	<br /><br /><br />
	<!--首次登录-->
	<div class="first-login mui-hidden">
		<div class="text">恭喜您商品已经兑换成功<br/>将尽快为您送达</div>
		<button type="button">再逛逛</button>
	</div>
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" src="js/distpicker.data.js" ></script>
	<script type="text/javascript" src="js/distpicker.js" ></script>
	<script type="text/javascript" charset="utf-8">
      	mui.init();
      	var mask=mui.createMask(callback);
      	function callback(){
      		$(".first-login").addClass("mui-hidden");
      	}
      	mui.ajax(H_SRC+'/amier/index/address_detail',{
			data:{
				token:token,
			},
			dataType:'json',
			type:'post',
			timeout:10000,             
			success:function(data){
				var dataurl=data.data;
				if(data.code == 1){
					$("#name").val(dataurl.name);
					if(dataurl.sex==1){
						$("#sex").val("男")
					}else if(dataurl.sex==2){
						$("#sex").val("女")
					}else{
						$("#sex").val("其他")
					}
					$("#tel").val(dataurl.tel);
					$("#email").val(dataurl.youbian);
					$("#province").val(dataurl.province);
					$("#city").val(dataurl.city);
					$("#area").val(dataurl.area);
					$("#address").val(dataurl.address);
				}else{
					mui.toast(data.msg);
				}
			},
			error:function(){
				
			}
		}) 
      	function sub(){
      		var name=$("#name").val();
      		var sex=$("#sex").children('option:selected').attr("data-type");
      		var tel=$("#tel").val();
      		var youbian=$("#email").val();
      		var province=$("#province").children('option:selected').val();
      		var city=$("#city").children('option:selected').val();
      		var area=$("#area").children('option:selected').val();
      		var address=$("#address").val();
      		mui.ajax(H_SRC+'/amier/user/edit_address',{
				data:{
					token:token,
					name:name,
					sex:sex,
					tel:tel,
					youbian:youbian,
					province:province,
					city:city,
					area:area,
					address:address,
				},
				dataType:'json',
				type:'post',
				timeout:10000,             
				success:function(data){
					var dataurl=data.data;
					if(data.code == 1){
						mui.toast("地址保存成功")
					}else{
						mui.toast(data.msg);
					}
				},
				error:function(){
					
				}
			}) 
      	}
    </script>
</body>
</html>